/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package schedulerManagerment.SeekerManager.gui;

import Application.MarvellFrame;
import DataServices.Validate;
import connection.Configuration;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
import schedulerManagerment.SeekerManager.entities.Field;
import schedulerManagerment.SeekerManager.entities.Seeker;
import schedulerManagerment.SeekerManager.entities.Skill;
import schedulerManagerment.SeekerManager.jdbc.Fields;
import schedulerManagerment.SeekerManager.jdbc.Seekers;

/**
 *
 * @author Tngoc
 */
public class SeekerManagerForm extends javax.swing.JFrame implements MarvellFrame {

    private Seekers seekers;
    private DefaultTableModel model;
    private int rowSelected;
    private Fields fields;
    private DefaultListModel listEditSeekerModel;
    private DefaultListModel listEditAddModel;
    private DefaultListModel listAddSeekerModel;
    private DefaultListModel listAddAddModel;
    private ArrayList<String> editSkillList;
    private ArrayList<Skill> skills;
    private Validate validate;

    private void setListModel() {
        listEditSeekerModel.clear();
        listEditAddModel.clear();
        listAddSeekerModel.clear();
        listAddAddModel.clear();
        try {
            Statement st = new Configuration().getConnect().createStatement();
            ResultSet rs = st.executeQuery("select * from Skill");
            while (rs.next()) {
                listEditAddModel.addElement(rs.getString("name"));
                listAddAddModel.addElement(rs.getString("name"));
                skills.add(new Skill(rs.getInt("ID"), rs.getString("name")));
            }
            st.getConnection().close();
        } catch (SQLException ex) {
            Logger.getLogger(SeekerManagerForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private Skill getSkill(String name) {
        for (Skill s : skills) {
            if (name.equals(s.getName())) {
                return s;
            }
        }
        return null;
    }

    private void userInit() {
        validate = new Validate();
        editSkillList = new ArrayList<>();
        skills = new ArrayList<>();
        listEditSeekerModel = new DefaultListModel();
        listEditAddModel = new DefaultListModel();
        listAddSeekerModel = new DefaultListModel();
        listAddAddModel = new DefaultListModel();
        listEditSeeker.setModel(listEditSeekerModel);
        listEditAdd.setModel(listEditAddModel);
        setListModel();
        this.seekers = new Seekers();
        setModelData();
        fields = new Fields();
        for (Field f : fields.getFields()) {
            comField.addItem(f.getName());
        }
        for (Field f : fields.getFields()) {
            comField1.addItem(f.getName());
        }
        btnEdit.setEnabled(false);
    }

    private void setModelData() {
        model = (DefaultTableModel) seekerTable.getModel();
        model.getDataVector().clear();
        for (Seeker s : seekers.getSeekerList()) {
            String gd;
            if (s.isGender()) {
                gd = "male";
            } else {
                gd = "female";
            }
            String stt;
            if (s.getStatus() == 0) {
                stt = "watting";
            } else if (s.getStatus() == 1) {
                stt = "inprogress";
            } else {
                stt = "done";
            }
            Object[] data = {s.getId(), s.getName(), gd, s.getEmail(), s.getField().getName(), s.getLocation(), stt};
            model.addRow(data);
        }
    }

    /**
     * Creates new form SeekerManagerForm
     */
    public SeekerManagerForm() {
        initComponents();
        userInit();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addFrame = new javax.swing.JFrame();
        btnSave1 = new javax.swing.JButton();
        btnCancel1 = new javax.swing.JButton();
        txtWebsite1 = new javax.swing.JTextField();
        comGender1 = new javax.swing.JComboBox();
        txtAddress1 = new javax.swing.JTextField();
        txtPhone1 = new javax.swing.JTextField();
        txtLocation1 = new javax.swing.JTextField();
        comField1 = new javax.swing.JComboBox();
        txtEmail1 = new javax.swing.JTextField();
        txtUname1 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jScrollPane1 = new javax.swing.JScrollPane();
        seekerTable = new javax.swing.JTable();
        btnRefresh = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtUname = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtLocation = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtPhone = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        comGender = new javax.swing.JComboBox();
        btnSave = new javax.swing.JButton();
        comField = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        txtWebsite = new javax.swing.JTextField();
        btnCancel = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        listEditAdd = new javax.swing.JList();
        btnEditRemove = new javax.swing.JButton();
        btnEditAdd = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        listEditSeeker = new javax.swing.JList();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jButton1 = new javax.swing.JButton();

        addFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        btnSave1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Check.png"))); // NOI18N
        btnSave1.setText("add");
        btnSave1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSave1ActionPerformed(evt);
            }
        });

        btnCancel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Minus Red Button.png"))); // NOI18N
        btnCancel1.setText("cancel");
        btnCancel1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancel1ActionPerformed(evt);
            }
        });

        comGender1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "male", "female" }));

        jLabel10.setText("name");

        jLabel11.setText("date of birth");

        jLabel12.setText("email");

        jLabel13.setText("field");

        jLabel14.setText("location");

        jLabel15.setText("phone");

        jLabel16.setText("address");

        jLabel17.setText("gender");

        jLabel18.setText("website");

        javax.swing.GroupLayout addFrameLayout = new javax.swing.GroupLayout(addFrame.getContentPane());
        addFrame.getContentPane().setLayout(addFrameLayout);
        addFrameLayout.setHorizontalGroup(
            addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(addFrameLayout.createSequentialGroup()
                        .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12))
                        .addGap(14, 14, 14)
                        .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtEmail1)
                            .addComponent(txtUname1)
                            .addComponent(jDateChooser2, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)))
                    .addGroup(addFrameLayout.createSequentialGroup()
                        .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(addFrameLayout.createSequentialGroup()
                                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel15)
                                    .addComponent(jLabel14)
                                    .addComponent(jLabel18))
                                .addGap(36, 36, 36))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, addFrameLayout.createSequentialGroup()
                                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel16)
                                    .addComponent(jLabel17))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtAddress1)
                            .addComponent(txtPhone1)
                            .addComponent(txtWebsite1)
                            .addComponent(txtLocation1)
                            .addComponent(comField1, javax.swing.GroupLayout.Alignment.TRAILING, 0, 133, Short.MAX_VALUE)
                            .addComponent(comGender1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(addFrameLayout.createSequentialGroup()
                        .addComponent(btnSave1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancel1)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        addFrameLayout.setVerticalGroup(
            addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtUname1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11)
                    .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtEmail1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtLocation1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtPhone1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtWebsite1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAddress1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(comGender1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancel1))
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        seekerTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "id", "name", "gender", "email", "Field", "Location", "status"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        seekerTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        seekerTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                seekerTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(seekerTable);

        btnRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Load.png"))); // NOI18N
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        btnEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/pencil.png"))); // NOI18N
        btnEdit.setText("edit");
        btnEdit.setEnabled(false);
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Add.png"))); // NOI18N
        btnAdd.setText("add");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Seeker infomation"));

        jLabel1.setText("name");

        txtUname.setEditable(false);

        jLabel2.setText("date of birth");

        txtEmail.setEditable(false);

        jLabel3.setText("email");

        jLabel4.setText("field");

        txtLocation.setEditable(false);

        jLabel5.setText("location");

        txtPhone.setEditable(false);

        jLabel7.setText("phone");

        txtAddress.setEditable(false);

        jLabel8.setText("address");

        jLabel9.setText("gender");

        comGender.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "male", "female" }));
        comGender.setEnabled(false);

        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/hand_pro.png"))); // NOI18N
        btnSave.setText("save");
        btnSave.setEnabled(false);
        btnSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                btnSaveMousePressed(evt);
            }
        });
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        comField.setEnabled(false);

        jLabel6.setText("website");

        txtWebsite.setEditable(false);

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Minus Red Button.png"))); // NOI18N
        btnCancel.setText("cancel");
        btnCancel.setEnabled(false);
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        listEditAdd.setEnabled(false);
        listEditAdd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listEditAddMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(listEditAdd);

        btnEditRemove.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/arrow-right-blue.png"))); // NOI18N
        btnEditRemove.setEnabled(false);
        btnEditRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditRemoveActionPerformed(evt);
            }
        });

        btnEditAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/arrow-left-blue.png"))); // NOI18N
        btnEditAdd.setEnabled(false);
        btnEditAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditAddActionPerformed(evt);
            }
        });

        listEditSeeker.setEnabled(false);
        listEditSeeker.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listEditSeekerMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(listEditSeeker);

        jDateChooser1.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(88, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(jLabel8)
                    .addComponent(jLabel6))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtUname)
                    .addComponent(txtEmail)
                    .addComponent(txtLocation)
                    .addComponent(txtPhone)
                    .addComponent(txtAddress)
                    .addComponent(txtWebsite)
                    .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancel))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(comField, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(comGender, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnEditAdd)
                            .addComponent(btnEditRemove))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(22, 22, 22))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(84, 84, 84)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(comGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtUname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(comField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(9, 9, 9)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txtLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtWebsite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btnEditAdd)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnEditRemove)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnSave, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(63, 63, 63))
        );

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Import Document.png"))); // NOI18N
        jButton1.setText("back");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnRefresh)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAdd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEdit))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 565, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnRefresh)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnAdd)
                        .addComponent(btnEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void seekerTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_seekerTableMouseClicked
        // TODO add your handling code here:
        rowSelected = seekerTable.getSelectedRow();
        if (rowSelected != -1) {
            showInfo();
        }
    }//GEN-LAST:event_seekerTableMouseClicked

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        editSeeker();
    }//GEN-LAST:event_btnEditActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        showInfo();
        setEnable(false);
        editSkillList.clear();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        int id = Integer.parseInt(model.getValueAt(rowSelected, 0).toString());
        String name = txtUname.getText();
        SimpleDateFormat dateformat = new SimpleDateFormat("MM-dd-yyyy");
        String birth = new StringBuilder(dateformat.format(jDateChooser1.getDate())).toString();
        String email = txtEmail.getText();
        int field = fields.getByName(comField.getSelectedItem().toString()).getId();
        String location = txtLocation.getText();
        String phone = txtPhone.getText();
        String address = txtAddress.getText();
        String gender;
        if ("male".equals(comGender.getSelectedItem().toString())) {
            gender = "1";
        } else {
            gender = "0";
        }
        String website = txtWebsite.getText();
        if (!validate.isEmpty(name)&&validate.isEmailValid(email)&&validate.isPhoneNumber(phone)&&!validate.isEmpty(address)&&validate.isWebValid(website)) {
            seekers.update(id, name, birth, email, field, location, phone, address, gender, website);
            setEnable(false);
        }
        seekers.refresh();
        setModelData();
        seekers.updateSkill(id, editSkillList);
        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/hand_pro.png")));
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        seekers.refresh();
        setModelData();
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        addFrame.pack();
        addFrame.setVisible(true);
        this.setEnabled(false);
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnSave1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSave1ActionPerformed
        String name = txtUname1.getText();
        SimpleDateFormat dateformat = new SimpleDateFormat("MM-dd-yyyy");
        String birth = new StringBuilder(dateformat.format(jDateChooser2.getDate())).toString();
        String email = txtEmail1.getText();
        int field = fields.getByName(comField1.getSelectedItem().toString()).getId();
        String location = txtLocation1.getText();
        String phone = txtPhone1.getText();
        String address = txtAddress1.getText();
        String gender;
        if ("male".equals(comGender1.getSelectedItem().toString())) {
            gender = "1";
        } else {
            gender = "0";
        }
        String website = txtWebsite1.getText();
        if(!validate.isEmpty(name)&&validate.isEmailValid(email)&&!validate.isEmpty(location)&&validate.isPhoneNumber(phone)&&!validate.isEmpty(address)&&validate.isWebValid(website)){
            int id = seekers.insert(name, birth, email, field, location, phone, address, gender, website);
        }else{
            JOptionPane.showMessageDialog(rootPane, "add error !");
        }
        setEnable(false);
        seekers.refresh();
        setModelData();
        btnCancel1.doClick();
    }//GEN-LAST:event_btnSave1ActionPerformed

    private void btnCancel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancel1ActionPerformed
        this.setEnabled(true);
        addFrame.setVisible(false);
        
    }//GEN-LAST:event_btnCancel1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.exitFrame();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void btnEditAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditAddActionPerformed
        editSkillList.add("insert into SeekerSkill_Detail values(" + model.getValueAt(rowSelected, 0) + "," + getSkill(listEditAdd.getSelectedValue().toString()).getId() + ")");
        listEditSeekerModel.addElement(listEditAdd.getSelectedValue());
        listEditAddModel.removeElement(listEditAdd.getSelectedValue());
        btnEditAdd.setEnabled(false);

    }//GEN-LAST:event_btnEditAddActionPerformed

    private void listEditAddMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listEditAddMouseClicked
        if (listEditAdd.getSelectedIndex() != -1) {
            btnEditAdd.setEnabled(true);
            btnEditRemove.setEnabled(false);
        }
    }//GEN-LAST:event_listEditAddMouseClicked

    private void listEditSeekerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listEditSeekerMouseClicked
        if (listEditSeeker.getSelectedIndex() != -1) {
            btnEditAdd.setEnabled(false);
            btnEditRemove.setEnabled(true);
        }
    }//GEN-LAST:event_listEditSeekerMouseClicked

    private void btnEditRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditRemoveActionPerformed
        editSkillList.add("remove from SeekerSkill_Detail where SeekerID=" + model.getValueAt(rowSelected, 0) + " and SkillID=" + getSkill(listEditSeeker.getSelectedValue().toString()).getId());
        listEditAddModel.addElement(listEditSeeker.getSelectedValue());
        listEditSeekerModel.removeElement(listEditSeeker.getSelectedValue());
        btnEditRemove.setEnabled(false);

    }//GEN-LAST:event_btnEditRemoveActionPerformed

    private void btnSaveMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSaveMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnSaveMousePressed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame addFrame;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnCancel1;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnEditAdd;
    private javax.swing.JButton btnEditRemove;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSave1;
    private javax.swing.JComboBox comField;
    private javax.swing.JComboBox comField1;
    private javax.swing.JComboBox comGender;
    private javax.swing.JComboBox comGender1;
    private javax.swing.JButton jButton1;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JList listEditAdd;
    private javax.swing.JList listEditSeeker;
    private javax.swing.JTable seekerTable;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtAddress1;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtEmail1;
    private javax.swing.JTextField txtLocation;
    private javax.swing.JTextField txtLocation1;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtPhone1;
    private javax.swing.JTextField txtUname;
    private javax.swing.JTextField txtUname1;
    private javax.swing.JTextField txtWebsite;
    private javax.swing.JTextField txtWebsite1;
    // End of variables declaration//GEN-END:variables

    private void showInfo() {
        setListModel();
        btnEdit.setEnabled(true);
        Seeker s = seekers.getById(Integer.parseInt(model.getValueAt(rowSelected, 0).toString()));
        for (Skill sk : s.getSkills()) {
            listEditSeekerModel.addElement(sk.getName());
            listEditAddModel.removeElement(sk.getName());
        }
        txtUname.setText(s.getName());
        jDateChooser1.setDate(s.getDateOfBirth());
        txtAddress.setText(s.getAddress());
        txtEmail.setText(s.getEmail());
        txtLocation.setText(s.getLocation());
        txtPhone.setText(s.getPhone());
        txtWebsite.setText(s.getWebsite());
        comField.setSelectedItem(s.getField().getName());
        comGender.setSelectedItem(model.getValueAt(rowSelected, 2));
    }

    private void editSeeker() {
        setEnable(true);
    }

    private void setEnable(boolean flag) {
        txtAddress.setEditable(flag);
        jDateChooser1.setEnabled(flag);
        txtEmail.setEditable(flag);
        txtLocation.setEditable(flag);
        txtPhone.setEditable(flag);
        txtUname.setEditable(flag);
        btnAdd.setEnabled(!flag);
        btnRefresh.setEnabled(!flag);
        btnSave.setEnabled(flag);
        txtWebsite.setEditable(flag);
        comField.setEnabled(flag);
        comGender.setEnabled(flag);
        btnCancel.setEnabled(flag);
        seekerTable.setEnabled(!flag);
        listEditAdd.setEnabled(flag);
        listEditSeeker.setEnabled(flag);
    }

    @Override
    public void startFrame(JFrame app) {
        try {
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            Logger.getLogger(SeekerManagerForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.root = app;
        this.setVisible(true);
        root.setEnabled(false);
    }

    @Override
    public void exitFrame() {
        root.setEnabled(true);
        this.setVisible(false);
    }
    private JFrame root;
}
